<template>
  <view>
    <view class="w100 pt-16 pl-24 pr-24">
      
      <view class="p-all-30 w100 bgff br-10 mb-20">
        <view class="fs-30 col333 fw-b mb-20">学生基础信息</view>
        
        <!-- <view class="w100 rows rowsm" style="flex-direction: row-reverse;">
          <view class="rows rowsm">
            <image src="/static/wd_gr.png" class="w-56 h-56 br-28 mr-12" mode=""></image>
            <view class="fs-24 col000 mr-28">{{data.stName || ''}}</view>
            <view class="fs-26 col888">({{data.stNumber || ''}})</view>
          </view>
        </view> -->
          <view class="fs-26 col888 mb-20">学生姓名: {{data.stName || ''}} ({{data.stNumber || ''}})</view>
          <view class="fs-26 col888 mb-20">学院: {{data.xyName}}</view>
          <view class="fs-26 col888 mb-20">年级: {{data.njName}}</view>
          <view class="fs-26 col888 mb-20">专业: {{data.zyName}}</view>
          <view class="fs-26 col888 mb-20">班级: {{data.bjName}}</view>
      </view>

      <view class="p-all-30 w100 bgff br-10 rowscl mb-20">
        <view class="w100 rowsb rowsm mb-16">
          <view class="fs-30 col333 fw-b" v-if="index == 0">劳动项目：{{data.name}}</view>
          <view class="fs-30 col333 fw-b" v-else>劳动项目：{{index == 1 ? '劳动总结报告' : index == 2 ? '劳动成果' : data.name ? data.name :'社会公益劳动'}}</view>
          <view class="w-126 h-50 br-25 rowsc rowsm fs-24" style="border: 2rpx solid #FF6560;color: #FF6560;" v-if="data.status == 3">被驳回</view>
          <view class="pl-10 pr-10 h-50 br-25 rowsc rowsm fs-24" style="border: 2rpx solid #4878FF;color: #4878FF;" v-if="data.status == 2">
            <text v-if="index == 0">{{data.dfCount || '0'}}积分</text>
            <!-- <text v-if="index == 0">{{data.dfCount}}</text> -->
            <text v-else>{{data.markNumber || '0'}}</text>
          </view>
          <view class="w-126 h-50 br-25 rowsc rowsm fs-24" style="border: 2rpx solid #FF9934;color: #FF9934;" v-if="data.status == 1">未审批</view>
        </view>
        <!-- <view class="fs-26 col888 mb-20" v-if="index == 0">分类：{{data.type == 1 ? '宿舍/教/实验劳动' : data.type == 2 ? '校内公共区劳动' : data.type == 3 ? '学校服务资源劳动' : data.type == 4 ? '劳动报告心得体会' : data.type == 5 ? '大学生创新创业' : data.type == 6 ? '互联网+报告' : data.type == 7 ? '演讲比赛/知识竞赛' : data.type == 8 ? '劳动执行/文明宿舍' : data.type == 9 ? '公益活动' : data.type == 10 ? '科技帮扶报告' : data.type == 11 ? '劳动周报告' : ''}}</view> -->
        <view class="fs-26 col888 mb-20" v-if="index == 0">分类：基础劳动/{{data.typeName}}</view>
        <view class="fs-26 col888 mb-20" v-else>分类：{{index == 1 ? '劳动总结报告' : index == 2 ? '劳动成果' : '社会公益劳动'}}</view>
        
        <view class="fs-26 col888 mb-20" v-if="data.bgTime">时间:{{data.bgTime || ''}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.dwName">主办单位:{{data.dwName}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.startTime && data.stopTime">劳动时间:{{data.startTime || ''}}至{{data.stopTime ||''}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.position">劳动地点:{{data.position}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.jbName">级别:{{data.jbName}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.djName">等级:{{data.djName}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.wcName">位次:{{data.wcName}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.proLdUserList && data.proLdUserList[0]">负责人:{{data.proLdUserList[0].stName || ''}}</view>
        <view class="fs-26 col888 mb-20">提交时间:{{data.createTime || ''}}</view>
        <view class="fs-26 col888 mb-20" v-if="data.status == 2 || data.status == 3">审批时间:{{data.opTime || ''}}</view>
      </view>
      
      <view class="p-all-30 w100 bgff br-10 mb-20">
        <view class="fs-30 col333 fw-b mb-20">劳动过程说明</view>
        <view class="fs-26 col888">{{data.content}}</view>
      </view>
      
      <view class="p-all-30 w100 bgff br-10 mb-20">
        <view class="fs-30 col333 fw-b mb-20">附件</view>
        <!-- <view class="fs-26 col888">劳动过程</view> -->
        <view v-for="item in data.proFileList" :key="item.id">
          <image :src="item.file" class="w-200 h-200 br-20" v-if="item.fileType == 'image'" mode="aspectFill" @click="openImg(item)"></image>
          <video :src="item.file" class="w-200 h-200 br-20" v-if="item.fileType == 'video'"></video>
          <view class="w100 h-140 br-10 rows rowsm pl-40" style="background-color: #F7F6FA;" v-if="item.fileType == 'file'" @click="openFile(item.file)">
            <image src="/static/file.png" class="w-60 h-60 mr-20" mode=""></image>
            <view class="fs-28 col888 w100 one_overflow">{{item.fileName}}</view>
          </view>
        </view>
      </view>
      
      <view class="p-all-30 w100 bgff br-10 mb-20" v-if="index != 0 && data.status == 1">
        <view class="fs-30 col333 fw-b mb-20">审批</view>
         <view class="w100 p-all-24 br-12" style="background-color: #F7F8FA;" v-if="data.status == 1">
          <picker mode="selector" :range="scoreList" range-key="name" @change="changeScore">
          <view class="rowsb rowsm w100">
            <view class="fs-26 " style="color:#9AA2B5;">{{scoreList[scoreIndex].name || '请打分'}}</view>
            <image src="/static/icon_1jt.png" class="w-20 h-20" mode=""></image>
          </view>
        </picker>
        </view>
        
      </view>
      <view class="p-all-30 w100 bgff br-10 mb-20" v-if="index != 0 && data.status == 2">
        <view class="fs-30 col333 fw-b mb-20">审批结果</view>
        <view class="rowsb rowsm w100">
          <view class="fs-26 col000">{{data.markNumber}}</view>
          <!-- <image src="/static/icon_1jt.png" class="w-20 h-20" mode=""></image> -->
        </view>
      </view>
      
      <view class="p-all-30 w100 bgff br-10 mb-20">
        <view class="fs-30 col333 fw-b mb-20">{{data.status == 3 ? '驳回原因' : '评语'}}</view>
        <view class="w100 p-all-24 br-12" style="background-color: #F7F8FA;" v-if="data.status == 1">
          <textarea value="" placeholder="请输入评语" placeholder-style="color:#9AA2B5;" placeholder-class="fs-26" auto-height class="w100" v-model="content" />
        </view>
        <view class="fs-26 col333" v-else>{{data.markName || ''}}</view>
      </view>
    </view>
    
    <view class="w100 h-140"></view>
    
   <!-- <view class="w100 rowsc rowsm fixed" style="bottom: 40rpx;">
      <view class="w-702 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);" v-if="data.status == 3">重新填写</view>
    </view> -->
	
    
    <view class="w100 rowsa rowsm fixed" style="bottom: 40rpx;" v-if="data.status == 1">
      <view class="w-304 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#FFC234,#FF9A30);" @click="$refs.popup.open()">驳回</view>
      <view class="w-304 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);" @click="pass()">通过</view>
    </view>
    
    <!-- <view class="w100 rowsc rowsm fixed" style="bottom: 40rpx;">
      <view class="w-702 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);">确定</view>
    </view> -->
    
    
    <uni-popup ref="popup" type="center" :is-mask-click="false">
      <view class="w-670 h-542 br-20 bgff pt-32 pl-24 pr-24">
        <view class="w100 rowsc rowsm fs-32 col000 fw-b mb-34">提示</view>
        <view class="w100 h-240 br-12 p-all-24 mb-60" style="background-color: #F7F8FA;">
          <textarea value="" placeholder="请输入驳回理由" placeholder-class="fs-28" class="w100 h100" placeholder-style="color:#9AA2B5;" v-model="noPassContent" />
        </view>
        <view class="w100 rowsa rowsm">
          <view class="w-280 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#FFC234,#FF9A30);" @click="$refs.popup.close()">取消</view>
          <view class="w-280 h-84 br-42 rowsc rowsm colfff fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);" @click="noPass()">确定</view>
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        id:'',
        data:{},
        scoreList:[],
		scoreIndex: 0,
		content:'',
		noPassContent:'',
    index:''
      };
    },
    onLoad(e) {
      this.id = e.id
      // this.index = e.index
      console.log('index---->',this.index,e)
       if(e.index == '-1' && e.ldType){
        this.index = e.ldType
         console.log('index---->',this.index)
      }else{
        this.index = e.index
      }
      this.getInfo()
	  this.getScoreList()
    },
    onReady() {
      // this.$refs.popup.open()
    },
    methods:{
		noPass(){
			if(this.index == 0){
        if(!this.noPassContent) return this.$tools.showtt('请输入原因')
        let data = {
        	id:this.id,
        	markName:this.noPassContent
        }
        this.$tools.axiosFromToken('POST','prold/reject',[{...data}],'加载中').then(res => {
        	this.$tools.showtt(res.msg)
        	if(res.code != 200) return
        	setTimeout(() => {
        		this.$tools.goBack(1)
        	},1000)
        })
      }else {
        if(this.index == 1){
          if(!this.noPassContent) return this.$tools.showtt('请输入原因')
          let data = {
          	id:this.id,
          	markName:this.noPassContent
          }
          this.$tools.axiosFromToken('POST','proldzj/reject',{...data},'加载中').then(res => {
          	this.$tools.showtt(res.msg)
          	if(res.code != 200) return
          	setTimeout(() => {
          		this.$tools.goBack(1)
          	},1000)
          })
        }
        if(this.index == 2){
          if(!this.noPassContent) return this.$tools.showtt('请输入原因')
          let data = {
          	id:this.id,
          	markName:this.noPassContent
          }
          this.$tools.axiosFromToken('POST','proldcg/reject',{...data},'加载中').then(res => {
          	this.$tools.showtt(res.msg)
          	if(res.code != 200) return
          	setTimeout(() => {
          		this.$tools.goBack(1)
          	},1000)
          })
        }
        if(this.index == 3){
          if(!this.noPassContent) return this.$tools.showtt('请输入原因')
          let data = {
          	id:this.id,
          	markName:this.noPassContent
          }
          this.$tools.axiosFromToken('POST','proldgy/reject',{...data},'加载中').then(res => {
          	this.$tools.showtt(res.msg)
          	if(res.code != 200) return
          	setTimeout(() => {
          		this.$tools.goBack(1)
          	},1000)
          })
        }
      }
		},
		pass(){
      if(this.index != 0 && this.data.status == 1){
        if(!this.scoreIndex) return this.$tools.showtt('请选择分数')
      }
			if(this.index == 0) {
        // if(!this.content) return this.$tools.showtt('请输入评语')
        let data = {
        	id:this.id,
        	// markNumber:this.scoreList[this.scoreIndex].name,
        	markName:this.content
        }
        this.$tools.axiosFromToken('POST','prold/pass',[{...data}],'加载中').then(res => {
        	this.$tools.showtt(res.msg)
        	if(res.code != 200) return
        	setTimeout(() => {
        		this.$tools.goBack(1)
        	},1000)
        })
      }else {
        if(this.index == 1){
          // if(!this.content) return this.$tools.showtt('请输入评语')
          let data = {
            id:this.id,
            markNumber:this.scoreList[this.scoreIndex].name,
            fsId:this.scoreList[this.scoreIndex].id,
            markName:this.content
          }
          
          this.$tools.axiosFromToken('POST','proldzj/pass',{...data},'加载中').then(res => {
            this.$tools.showtt(res.msg)
            if(res.code != 200) return
            setTimeout(() => {
            	this.$tools.goBack(1)
            },1000)
          })
        }
        if(this.index == 2){
          // if(!this.content) return this.$tools.showtt('请输入评语')
          let data = {
            id:this.id,
            markNumber:this.scoreList[this.scoreIndex].name,
            fsId:this.scoreList[this.scoreIndex].id,
            markName:this.content
          }
          
          this.$tools.axiosFromToken('POST','proldcg/pass',{...data},'加载中').then(res => {
            this.$tools.showtt(res.msg)
            if(res.code != 200) return
            setTimeout(() => {
            	this.$tools.goBack(1)
            },1000)
          })
        }
        if(this.index == 3){
          // if(!this.content) return this.$tools.showtt('请输入评语')
          let data = {
            id:this.id,
            markNumber:this.scoreList[this.scoreIndex].name,
            fsId:this.scoreList[this.scoreIndex].id,
            markName:this.content
          }
          
          this.$tools.axiosFromToken('POST','proldgy/pass',{...data},'加载中').then(res => {
            this.$tools.showtt(res.msg)
            if(res.code != 200) return
            setTimeout(() => {
            	this.$tools.goBack(1)
            },1000)
          })
        }
      }
		},
		changeScore(e){
			this.scoreIndex = e.detail.value
		},
		getScoreList(){
			this.$tools.axiosFromToken('POST','proldconfig/listFs',{},'加载中').then(res => {
				if(res.code != 200) return this.$tools.showtt(res.msg)
				let {rows} = res
				this.scoreList = rows
			})
		},
      getInfo(){
        if(this.index == 0) {
          this.$tools.axiosFromToken('POST','prold/getById',{id:this.id},'加载中').then(res => {
            if(res.code != 200) return this.$tools.showtt(res.msg)
            let {data} = res
            if(data.proFileList.length > 0){
              data.proFileList.forEach(item =>{
                item.file = this.$tools.avatarUrl + item.file
              })
            }
            this.data = data
            uni.setNavigationBarTitle({
              title:data.name
            })
          })
        }else {
          if(this.index == 1){
            this.$tools.axiosFromToken('POST','proldzj/getById',{id:this.id},'加载中').then(res => {
              if(res.code != 200) return this.$tools.showtt(res.msg)
              let {data} = res
              if(data.proFileList.length > 0){
                data.proFileList.forEach(item =>{
                  item.file = this.$tools.avatarUrl + item.file
                })
              }
              this.data = data
              uni.setNavigationBarTitle({
                title:'劳动总结报告'
              })
            })
          }
          if(this.index == 2){
            this.$tools.axiosFromToken('POST','proldcg/getById',{id:this.id},'加载中').then(res => {
              if(res.code != 200) return this.$tools.showtt(res.msg)
              let {data} = res
              if(data.proFileList.length > 0){
                data.proFileList.forEach(item =>{
                  item.file = this.$tools.avatarUrl + item.file
                })
              }
              this.data = data
              uni.setNavigationBarTitle({
                title:'劳动成果'
              })
            })
          }
          if(this.index == 3){
            this.$tools.axiosFromToken('POST','proldgy/getById',{id:this.id},'加载中').then(res => {
              if(res.code != 200) return this.$tools.showtt(res.msg)
              let {data} = res
              if(data.proFileList.length > 0){
                data.proFileList.forEach(item =>{
                  item.file = this.$tools.avatarUrl + item.file
                })
              }
              this.data = data
              uni.setNavigationBarTitle({
                title:'社会公益劳动'
              })
            })
          }
        }
      },
      openImg(url){
        // uni.previewImage({
        //   urls:[url]
        // })
        let urlList = [];
        this.data.proFileList.forEach(item => {
          if (url.fileType == 'image') {
            urlList.push(item.file)
          }
        });
        uni.previewImage({
          current: url,
          urls: urlList,
          loop: false,
          indicator: 'number',
        });
      },
      openFile(url){
        uni.downloadFile({
          url:url,
          success(res) {
            uni.openDocument({
              filePath:res.tempFilePath,
              showMenu:true,
              complete(msg) {
                console.log(msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>


</style>
